package com.sc.design.singleton.limited;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/***
 * 假设限定产生3个
 */

public class Emperor{
    private static List<Emperor> emperorList = new ArrayList<>();
    private static List<String> nameList = new ArrayList<>();
    private static int Max_num =3;
    private static int count = 0;
    static {
        for (int i=0;i<Max_num;i++){
            emperorList.add(new Emperor("皇帝"+i));
        }
    }
    private Emperor(String name){
        nameList.add(name);
    }
    public static Emperor getInstance(){
        Random random = new Random();
         count = random.nextInt(Max_num);
        return emperorList.get(count);
    }

    public  void say(){
        System.out.println(nameList.get(count));
    }

}



